package com.office.forum.manage.category.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.forum.manage.category.domain.ForumPostCategory;
import com.office.forum.manage.category.service.IForumPostCategoryService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 帖子分类Controller
 * 
 * @author ruoyi
 * @date 2025-05-31
 */
@RestController
@RequestMapping("/posts/category")
public class ForumPostCategoryController extends BaseController
{
    @Autowired
    private IForumPostCategoryService forumPostCategoryService;

    /**
     * 查询帖子分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ForumPostCategory forumPostCategory)
    {
        startPage();
        List<ForumPostCategory> list = forumPostCategoryService.selectForumPostCategoryList(forumPostCategory);
        return getDataTable(list);
    }

    /**
     * 导出帖子分类列表
     */
    @Log(title = "帖子分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumPostCategory forumPostCategory)
    {
        List<ForumPostCategory> list = forumPostCategoryService.selectForumPostCategoryList(forumPostCategory);
        ExcelUtil<ForumPostCategory> util = new ExcelUtil<ForumPostCategory>(ForumPostCategory.class);
        util.exportExcel(response, list, "帖子分类数据");
    }

    /**
     * 获取帖子分类详细信息
     */
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(forumPostCategoryService.selectForumPostCategoryByCategoryId(categoryId));
    }

    /**
     * 新增帖子分类
     */
    @Log(title = "帖子分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumPostCategory forumPostCategory)
    {
        return toAjax(forumPostCategoryService.insertForumPostCategory(forumPostCategory));
    }

    /**
     * 修改帖子分类
     */
    @Log(title = "帖子分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumPostCategory forumPostCategory)
    {
        return toAjax(forumPostCategoryService.updateForumPostCategory(forumPostCategory));
    }

    /**
     * 删除帖子分类
     */
    @Log(title = "帖子分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(forumPostCategoryService.deleteForumPostCategoryByCategoryIds(categoryIds));
    }
}
